package com.xgpro.pc.rolemanage.service.impl;

import com.xgpro.domain.rolemanage.entity.Token;
import com.xgpro.mapper.rolemanage.TokenMapper;
import com.xgpro.pc.rolemanage.service.TokenService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @program: xgpro__dev
 * @description:
 * @author: likai
 * @create: 2019-11-03 21:13
 **/
@Service
@Transactional
public class TokenServiceImpl implements TokenService {

    @Resource
    private TokenMapper tokenMapper;

    @Override
    public Token findToken() {
        List<Token> tokens = tokenMapper.selectAll();
        if (!CollectionUtils.isEmpty(tokens)){
            return tokens.get(0);
        }else {
            return null;
        }

    }

    @Override
    public Token findTokenTicket() {
        List<Token> tokens = tokenMapper.selectAll();
        if (!CollectionUtils.isEmpty(tokens)){
            return tokens.get(0);
        }else {
            return null;
        }
    }

    @Override
    public Integer update(Date date, String s) {

        return tokenMapper.update(date,s);
    }

    @Override
    public Integer updateticket(Date date, String s,String ticket) {

        return tokenMapper.updateticket(date,s,ticket);
    }

    @Override
    public Integer insert(Token token) {
        return tokenMapper.insert(token);
    }
}
